﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MESMian.EntityMapping
{
    public class ProductsMapping : IEntityTypeConfiguration<Products>
    {
        public void Configure(EntityTypeBuilder<Products> builder)
        {
            builder.ToTable("Products");
            builder.HasKey(p => p.ProductId);
            builder.Property(p => p.ProductId)
                .HasComment("产品主键，自动编号");

            builder.Property(p => p.ProductCode)
                .IsRequired()
                .HasColumnType("varchar(20)")
                .HasComment("产品编码，不能重复");

            builder.Property(p => p.ProductName)
                .IsRequired()
                .HasColumnType("varchar(80)")
                .HasComment("产品名称，不能重复");

            builder.Property(p => p.MaintainerId)
                 .IsRequired()
                 .HasComment("产品维护人，外键(Users)");

            builder.Property(p => p.MaintenanceTime)
                .IsRequired()
                .HasColumnType("dateTime")
                .HasComment("维护时间");

            builder.Property(p => p.ProductCategoryId)
                .IsRequired()
                .HasColumnType("int")
                .HasComment("产品类型，外键（ProductCategories）");


            builder.Property(p => p.ProductSpecId)
                .IsRequired()
                .HasColumnType("int")
                .HasComment("产品规格，外键（ProductSpecs）");

            builder.Property(p => p.ProductUnitId)
               .IsRequired()
               .HasColumnType("int")
               .HasComment("单位，外键（Units）");


            builder.Property(p => p.ProductImage)
             .HasColumnType("image")
             .HasComment("产品图片");

            builder.Property(p => p.Status)
               .IsRequired()
               .HasColumnType("int")
               .HasComment("数据状态（0正常，1删除）默认值0")
               .HasDefaultValue(0);

            builder.Property(p => p.CreateUserId)
            .HasColumnType("int")
            .IsRequired()
            .HasComment("创建人，外键（Users）");

            builder.Property(p => p.CreateTime)
                .HasColumnType("dateTime default getdate()")
                .IsRequired()
                .HasComment("创建时间，默认值为当前时间");

            builder.Property(p => p.LastUpdateUserId)
                .HasColumnType("int")
                .HasComment("最后一次修改人，外键（Users）");

            builder.Property(p => p.LastUpdateTime)
                .HasColumnType("dateTime")
                .HasComment("最后一次修改时间");

        }
    }
}
